<?php

Yii::import('application.models._base.BasePageType');

class PageType extends BasePageType {
    
    public function rules() {
		return array(
			array('page_name', 'required'),
			array('parent_id, status', 'numerical', 'integerOnly'=>true),
			array('page_name', 'length', 'max'=>45),
			array('parent_id, status', 'default', 'setOnEmpty' => true, 'value' => 0),
			array('id, page_name, parent_id, status', 'safe', 'on'=>'search'),
		);
	}

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function relations() {
        return array(
            'pageContents' => array(self::HAS_MANY, 'PageContent', 'page_type_id'),
            'children' => array(self::HAS_MANY, 'PageType', 'parent_id'),
            'parent' => array(self::BELONGS_TO, 'PageType', 'parent_id', 'condition' => 't.parent <> 0'),
        );
    }
    
    public static function label($n = 1) {
		return Yii::t('app', 'Page Name|Page Names', $n);
	}


    public function getCategoryname($id) {
        if ($id == 0):
            $name = "No subcategory";
        else:
            $model = new PageType;
            $mydata = $model->findByPk($id);
            $name = $mydata['page_name'];
        endif;
        return $name;
    }

}
